import request from '@/request'
import type { CategoryTypeData, TopicTypeData } from '@/common/topic/topicType'
import type { ApiResponse } from '@/common/requestType'
import type { Data } from '@/common/topic/topicDetailType'
import type { TopicDetailTabbarType } from '@/common/topic/topicDetailType'
import type { SearchUserType } from '@/common/user/user'

//获取分类列表api返回数据（注意：这个api接口已经在话题列表中使用，所以这里不需要再次调用，这个可以废弃该换）
export function getIndexCategory(
  type: string
): Promise<ApiResponse<CategoryTypeData[]>> {
  return request({
    url: `/category/${type}`,
    method: 'GET'
  })
}

export function getIndexList(
  category_id: number,
  page: number
): Promise<ApiResponse<Data>> {
  return request({
    url: `/category/${category_id}/article/${page}`,
    method: 'GET'
  })
}

// 关注
export function followList(user_id: number): Promise<ApiResponse<string>> {
  return request({
    url: `/add_follow/${user_id}`,
    method: 'POST'
  })
}

//取消关注 (已关注状态)
export function unFollowList(user_id: number): Promise<ApiResponse<string>> {
  return request({
    url: `/remove_follow/${user_id}`,
    method: 'POST'
  })
}

// 点赞api接口
export function addLike(
  article_id: number,
  type: string
): Promise<ApiResponse<string>> {
  return request({
    url: `/support/${type}/${article_id}`,
    method: 'POST'
  })
}

// 搜索帖子api接口
export function searchTieZi(
  page: number,
  keyword: string
): Promise<ApiResponse<TopicDetailTabbarType[]>> {
  return request({
    url: `/search/article/${page}?keyword=${keyword}`,
    method: 'GET'
  })
}

// 搜索用户api接口
export function searchUser(
  page: number,
  keyword: string
): Promise<ApiResponse<SearchUserType[]>> {
  return request({
    url: `/search/user/${page}?keyword=${keyword}`,
    method: 'GET'
  })
}

// 搜索话题api接口
export function searchHuaTi(
  page: number,
  keyword: string
): Promise<ApiResponse<TopicTypeData[]>> {
  return request({
    url: `/search/topic/${page}?keyword=${keyword}`,
    method: 'GET'
  })
}
